from ..platform import what as m_what_platform

main_window_handle = None

def find_process_main_window(uprocess):
    """
    :return native window handle
    ：note no thread-safe
    """
    pid = uprocess.id()

    if m_what_platform.running_os["type"] == "windows":
        from ..sysapi.win32 import windows

        def _enum_cb(hWnd, pid):
            global main_window_handle

            thread_id, process_id = windows.GetWindowThreadProcessId(hWnd)
            if process_id == pid:
                main_window_handle = hWnd
                return False
            return True

        windows.EnumWindows(_enum_cb, pid)

        return main_window_handle
    else:
        raise NotImplementedError